###统计gain.loss.filpping.smilar
setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM/")
library(openxlsx)
filea=read.csv("20201112做汇总表/all.FDR.sig.at.least.one.add.direction.same.diff.csv",head=T)
filea$id=paste(filea$Chr,filea$Start,sep = ":")
filea1=filea[filea$FDR.sig>1,]
file=read.table("E:/5hmc_file/2_5hmc_yjp_bam/ASM/20210316LIBD.eQTL处理/53K.add.GWAS.eQTL.DEG.motif.for.analysis.txt",header=T,sep="\t")
file=file[!duplicated(file$id),]	#对TF去重
file1=file[file$pattern.not.rm.dupl.num.DC>1,]
file2=file1[file1$BF_in_DC>1,]
file3=file1[file1$BF_in_DC>10,]

file3$group.beta.DC.con="normal_nosig"
file3[file3$DC.con.beta0<0&file3$DC.con.pvalue<0.05,]$group.beta.DC.con="normal_down"
file3[file3$DC.con.beta0>0&file3$DC.con.pvalue<0.05,]$group.beta.DC.con="normal_up"

file3$group.beta.DC.case="tumor_nosig"
file3[file3$DC.case.beta0<0&file3$DC.case.pvalue<0.05,]$group.beta.DC.case="tumor_down"
file3[file3$DC.case.beta0>0&file3$DC.case.pvalue<0.05,]$group.beta.DC.case="tumor_up"

file3$group.DC.beta=paste(file3$group.beta.DC.con,file3$group.beta.DC.case,sep=":")


file2$group.beta.DC.con="normal_nosig"
file2[file2$DC.con.beta0<0&file2$DC.con.pvalue<0.05,]$group.beta.DC.con="normal_down"
file2[file2$DC.con.beta0>0&file2$DC.con.pvalue<0.05,]$group.beta.DC.con="normal_up"

file2$group.beta.DC.case="tumor_nosig"
file2[file2$DC.case.beta0<0&file2$DC.case.pvalue<0.05,]$group.beta.DC.case="tumor_down"
file2[file2$DC.case.beta0>0&file2$DC.case.pvalue<0.05,]$group.beta.DC.case="tumor_up"

file2$group.DC.beta=paste(file2$group.beta.DC.con,file2$group.beta.DC.case,sep=":")
table(file2$group.DC.beta)
